package com.diyunapp.xilinapp.details;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.diyunapp.xilinapp.R;
import com.diyunapp.xilinapp.adapters.RecycleViewGridAdapter;
import com.diyunapp.xilinapp.adapters.RecycleViewYHQAdapter;
import com.diyunapp.xilinapp.bean.YouHuiQuanBean;
import com.diyunapp.xilinapp.bean.YouLikeGoodsBean;
import com.diyunapp.xilinapp.main.MainActivity;
import com.diyunapp.xilinapp.myapi.OnRecyclerViewItemClickListener;
import com.diyunapp.xilinapp.selfdefine.LocalImageHolderView;
import com.diyunapp.xilinapp.selfdefine.StatusBarActivity;
import com.diyunapp.xilinapp.utils.FormatConfirm;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.nostra13.universalimageloader.core.ImageLoader;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by NIDAYE on 2016/6/28.
 */
public class StoreActivity extends StatusBarActivity implements View.OnClickListener {
    @Bind(R.id.store_goback_ib)
    ImageButton storeGobackIb;
    @Bind(R.id.store_savestore_iv)
    ImageView storeSavestoreIv;
    @Bind(R.id.store_savestore_tv)
    TextView storeSavestoreTv;
    @Bind(R.id.store_savestore_ll)
    LinearLayout storeSavestoreLl;
    @Bind(R.id.store_theimg_iv)
    ImageView storeTheimgIv;
    @Bind(R.id.store_thename_tv)
    TextView storeThenameTv;
    @Bind(R.id.storemain_credit_ll)
    LinearLayout storemainCreditLl;
    @Bind(R.id.hasbeen_saveed_timetv)
    TextView hasbeenSaveedTimetv;
    @Bind(R.id.store_allgoods_ll)
    LinearLayout storeAllgoodsLl;
    @Bind(R.id.store_youhuiquan_rv)
    RecyclerView storeYouhuiquanRv;
    @Bind(R.id.store_convenientBanner)
    ConvenientBanner storeConvenientBanner;
    @Bind(R.id.store_tuijiangoods_rv)
    RecyclerView storeTuijiangoodsRv;
    @Bind(R.id.store_newgoods_rv)
    RecyclerView storeNewgoodsRv;
    private List<String> picUrlList = new ArrayList<>();
    private int[] bannerPoint;

    private GridLayoutManager gridYHQLayoutManager;
    private List<YouHuiQuanBean> goodsYHQLists;
    private RecycleViewYHQAdapter recycleYHQViewAdapter;

    private GridLayoutManager gridTJLayoutManager;
    private List<YouLikeGoodsBean> goodsTJLists;
    private RecycleViewGridAdapter recycleTJViewAdapter;

    private GridLayoutManager gridNewLayoutManager;
    private List<YouLikeGoodsBean> goodsNewLists;
    private RecycleViewGridAdapter recycleNewViewAdapter;

    private View topViewTj;
    private TextView textViewTj;

    private View topViewNew;
    private TextView textViewNew;

    private String StoreID;
    private String store_name;
    private int is_fav = 0;

    private View headView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.good_store_layout);
        ButterKnife.bind(this);

        StoreID = getIntent().getStringExtra("StoreId");
        initViews();
        getStoreInfo();
        getYHQInfo();
    }

    private void initViews() {

        headView = findViewById(R.id.store_menubar_inc);
        super.MenuWidget(headView);

        storeGobackIb.setOnClickListener(this);
        storeAllgoodsLl.setOnClickListener(this);
        storeSavestoreLl.setOnClickListener(this);
        topViewTj = LayoutInflater.from(this).inflate(R.layout.store_recyclertop_layout, null);
        textViewTj = (TextView) topViewTj.findViewById(R.id.store_goodstitle_tv);
        topViewNew = LinearLayout.inflate(this, R.layout.store_recyclertop_layout, null);
        textViewNew = (TextView) topViewNew.findViewById(R.id.store_goodstitle_tv);

        initYHQView();
        initTuiJianView();
        initNewView();
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.store_goback_ib:
                finish();
                break;
            case R.id.store_allgoods_ll:
                Intent allgoodsInt = new Intent(this, SearchResultActivity.class);
                allgoodsInt.putExtra("SearchKeyType", "keyword");
                allgoodsInt.putExtra("SearchKeyWord", "店铺搜索");
                allgoodsInt.putExtra("SearchStoreId", StoreID);
                allgoodsInt.putExtra("SearchStoreName", store_name);
                startActivity(allgoodsInt);
                break;
            case R.id.store_savestore_ll:
                if (MainActivity.myLogin.isLoginState()) {
                    storeSaveSet();
                } else {
                    Toast.makeText(getApplication(), "您还没有登录！", Toast.LENGTH_SHORT).show();
                }
                break;
            default:
                break;
        }
    }

    private void initYHQView() {
        gridYHQLayoutManager = new GridLayoutManager(this, 2);
        goodsYHQLists = new ArrayList<>();
        recycleYHQViewAdapter = new RecycleViewYHQAdapter(goodsYHQLists);

        //以下是为RecycleView添加头尾的操作，暂不需要，屏蔽掉。
        //recycleTJViewAdapter.addHeadView(topViewTj);
        //recycleViewAdapter.addFootView(endView);

        //如果添加了头部或者尾部 就需要做相关的SpanSize的修改
        recycleYHQViewAdapter.setChangeGridLayoutManager(new RecycleViewYHQAdapter.ChangeGridLayoutManagerSpance() {
            @Override
            public void change(final int size, final boolean isAddHead, final boolean isAddFoot) {
                gridYHQLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
                    @Override
                    public int getSpanSize(int position) {
                        int spanSzie = 1;
                        if (isAddHead) {
                            if (position == 0) {
                                spanSzie = gridYHQLayoutManager.getSpanCount();
                            }
                        }

                        if (isAddFoot) {
                            if (position == size) {
                                spanSzie = gridYHQLayoutManager.getSpanCount();
                            }
                        }
                        return spanSzie;
                    }
                });
            }
        });

        storeYouhuiquanRv.setLayoutManager(gridYHQLayoutManager);
        storeYouhuiquanRv.setAdapter(recycleYHQViewAdapter);
        recycleYHQViewAdapter.setOnItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int data) {
                //Todo
                if (MainActivity.myLogin.isLoginState()) {
                    changeYHQ(goodsYHQLists.get(data).getVoucher_id());
                } else {
                    Toast.makeText(getApplication(), "您还没有登录！", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    private void initTuiJianView() {
        gridTJLayoutManager = new GridLayoutManager(this, 2);
        goodsTJLists = new ArrayList<>();
        recycleTJViewAdapter = new RecycleViewGridAdapter(goodsTJLists);

        //以下是为RecycleView添加头尾的操作，暂不需要，屏蔽掉。
        recycleTJViewAdapter.addHeadView(topViewTj);
        //recycleViewAdapter.addFootView(endView);

        //如果添加了头部或者尾部 就需要做相关的SpanSize的修改
        recycleTJViewAdapter.setChangeGridLayoutManager(new RecycleViewGridAdapter.ChangeGridLayoutManagerSpance() {
            @Override
            public void change(final int size, final boolean isAddHead, final boolean isAddFoot) {
                gridTJLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
                    @Override
                    public int getSpanSize(int position) {
                        int spanSzie = 1;
                        if (isAddHead) {
                            if (position == 0) {
                                spanSzie = gridTJLayoutManager.getSpanCount();
                            }
                        }

                        if (isAddFoot) {
                            if (position == size) {
                                spanSzie = gridTJLayoutManager.getSpanCount();
                            }
                        }
                        return spanSzie;
                    }
                });
            }
        });

        storeTuijiangoodsRv.setLayoutManager(gridTJLayoutManager);
        storeTuijiangoodsRv.setAdapter(recycleTJViewAdapter);
        recycleTJViewAdapter.setOnItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int data) {
                //TODO
                Intent likeInt = new Intent(StoreActivity.this, GoodsDetailActivity.class);
                likeInt.putExtra("GoodId", goodsTJLists.get(data).getGoodId());
                startActivity(likeInt);
            }
        });
    }

    private void initNewView() {
        gridNewLayoutManager = new GridLayoutManager(this, 2);
        goodsNewLists = new ArrayList<>();
        recycleNewViewAdapter = new RecycleViewGridAdapter(goodsNewLists);

        //以下是为RecycleView添加头尾的操作，暂不需要，屏蔽掉。
        recycleNewViewAdapter.addHeadView(topViewNew);
        //recycleViewAdapter.addFootView(endView);

        //如果添加了头部或者尾部 就需要做相关的SpanSize的修改
        recycleNewViewAdapter.setChangeGridLayoutManager(new RecycleViewGridAdapter.ChangeGridLayoutManagerSpance() {
            @Override
            public void change(final int size, final boolean isAddHead, final boolean isAddFoot) {
                gridNewLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
                    @Override
                    public int getSpanSize(int position) {
                        int spanSzie = 1;
                        if (isAddHead) {
                            if (position == 0) {
                                spanSzie = gridNewLayoutManager.getSpanCount();
                            }
                        }

                        if (isAddFoot) {
                            if (position == size) {
                                spanSzie = gridNewLayoutManager.getSpanCount();
                            }
                        }
                        return spanSzie;
                    }
                });
            }
        });

        storeNewgoodsRv.setLayoutManager(gridNewLayoutManager);
        storeNewgoodsRv.setAdapter(recycleNewViewAdapter);
        recycleNewViewAdapter.setOnItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int data) {
                //TODO
                Intent likeInt = new Intent(StoreActivity.this, GoodsDetailActivity.class);
                likeInt.putExtra("GoodId", goodsNewLists.get(data).getGoodId());
                startActivity(likeInt);
            }
        });
    }

    private void initBanner() {
        //自定义你的Holder，实现更多复杂的界面，不一定是图片翻页，其他任何控件翻页亦可。
        storeConvenientBanner.setPages(
                new CBViewHolderCreator<LocalImageHolderView>() {
                    @Override
                    public LocalImageHolderView createHolder() {
                        return new LocalImageHolderView();
                    }
                }, picUrlList).startTurning(120000);
        //设置两个点图片作为翻页指示器，不设置则没有指示器，可以根据自己需求自行配合自己的指示器,不需要圆点指示器可用不设
        //.setPageIndicator(bannerPoint);
        //设置指示器的方向
        //.setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.ALIGN_PARENT_RIGHT);
        //设置翻页的效果，不需要翻页效果可用不设
        //.setPageTransformer(Transformer.DefaultTransformer);    集成特效之后会有白屏现象，新版已经分离，如果要集成特效的例子可以看Demo的点击响应。
        //convenientBanner.setManualPageable(false);//设置不能手动影响
    }

    private void getStoreInfo() {
        String url = "http://www.xilingou.com/mobile/index.php?act=goods&op=store_index&store_id=" + StoreID;
        if (MainActivity.myLogin.isLoginState()) {
            String meminfo = "&member_id=" + MainActivity.myLogin.getMemberid();
            url += meminfo;
        }
        HttpUtils http = new HttpUtils();
        http.configCurrentHttpCacheExpiry(2000);
        http.send(HttpRequest.HttpMethod.GET, url, new RequestCallBack<String>() {
                    @Override
                    public void onLoading(long total, long current, boolean isUploading) {
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        int result = parseProject(responseInfo.result);
                        switch (result) {
                            case 1:
                                break;
                            case 0:
                                Toast.makeText(getApplicationContext(), "读取店铺信息失败！", Toast.LENGTH_LONG).show();
                                break;
                            default:
                                break;
                        }
                    }


                    @Override
                    public void onStart() {

                    }

                    private int parseProject(String result) {
                        Log.i("zhangxiaoxidebug", "store_result=" + result);
                        try {
                            JSONObject jsObjectCode = new JSONObject(result);
                            int code = jsObjectCode.getInt("code");
                            if (code != 200) {
                                return 0;
                            }

                            JSONObject jsObjectDatas = jsObjectCode.getJSONObject("datas");

                            //store_info
                            {
                                JSONObject jsObjectStoreInfo = jsObjectDatas.getJSONObject("store_info");
                                store_name = jsObjectStoreInfo.getString("store_name");
                                String store_avatar = jsObjectStoreInfo.getString("store_avatar");
                                String store_banner = jsObjectStoreInfo.getString("store_banner");
                                //目前仅支持一张
                                picUrlList.add(store_banner);

                                int credit_num = jsObjectStoreInfo.getInt("store_credit_average");
                                setStoreCredit(credit_num);
                                String store_collect = jsObjectStoreInfo.getString("store_collect");
                                hasbeenSaveedTimetv.setText(store_collect+"次收藏");
                                is_fav = jsObjectStoreInfo.getInt("is_fav");

                                ImageLoader.getInstance().displayImage(store_avatar, storeTheimgIv, FormatConfirm.getOption());
                                storeThenameTv.setText(store_name);

                                if (is_fav > 0) {
                                    storeSavestoreIv.setImageDrawable(getResources().getDrawable(R.drawable.cang));
                                    storeSavestoreTv.setText("已收藏");
                                } else {
                                    storeSavestoreIv.setImageDrawable(getResources().getDrawable(R.drawable.dian_love));
                                    storeSavestoreTv.setText("收藏");
                                }

                                initBanner();
                            }

                            //推荐商品列表
                            {
                                JSONObject jsObjectTuiJian = jsObjectDatas.getJSONObject("tuijian");
                                JSONArray jsArrayTuiJianList = jsObjectTuiJian.getJSONArray("list");
                                if (jsArrayTuiJianList.length() > 0) {
                                    JSONObject jsObjectMokuaiTj = jsObjectTuiJian.getJSONObject("mokuai");
                                    String tuijianTitle = jsObjectMokuaiTj.getString("title");
                                    textViewTj.setText(tuijianTitle);
                                    goodsTJLists.clear();
                                    for (int good = 0; good < jsArrayTuiJianList.length(); good++) {
                                        JSONObject jsObjectTheGood = jsArrayTuiJianList.getJSONObject(good);
                                        String goodId = jsObjectTheGood.getString("goods_id");
                                        String goods_name = jsObjectTheGood.getString("goods_name");
                                        String goods_promotion_price = jsObjectTheGood.getString("goods_price");
                                        String goods_image = jsObjectTheGood.getString("goods_image");
                                        String goods_salenum = jsObjectTheGood.getString("goods_salenum");
                                        goodsTJLists.add(new YouLikeGoodsBean(goodId, goods_image, goods_name, goods_promotion_price, goods_salenum));
                                    }
                                    recycleTJViewAdapter.notifyDataSetChanged();
                                } else {
                                    textViewTj.setVisibility(View.GONE);
                                    storeTuijiangoodsRv.setVisibility(View.GONE);
                                }
                            }

                            //新品上架商品列表
                            {
                                JSONObject jsObjectNews = jsObjectDatas.getJSONObject("xinpin");
                                JSONArray jsArrayNewsList = jsObjectNews.getJSONArray("list");
                                if (jsArrayNewsList.length() > 0) {
                                    JSONObject jsObjectMokuaiNew = jsObjectNews.getJSONObject("mokuai");
                                    String newsTitle = jsObjectMokuaiNew.getString("title");
                                    textViewNew.setText(newsTitle);
                                    goodsNewLists.clear();
                                    for (int good1 = 0; good1 < jsArrayNewsList.length(); good1++) {
                                        JSONObject jsObjectTheGood = jsArrayNewsList.getJSONObject(good1);
                                        String goodId = jsObjectTheGood.getString("goods_id");
                                        String goods_name = jsObjectTheGood.getString("goods_name");
                                        String goods_promotion_price = jsObjectTheGood.getString("goods_price");
                                        String goods_image = jsObjectTheGood.getString("goods_image");
                                        String goods_salenum = jsObjectTheGood.getString("goods_salenum");
                                        goodsNewLists.add(new YouLikeGoodsBean(goodId, goods_image, goods_name, goods_promotion_price, goods_salenum));
                                    }
                                    recycleNewViewAdapter.notifyDataSetChanged();
                                } else {
                                    textViewNew.setVisibility(View.GONE);
                                    storeNewgoodsRv.setVisibility(View.GONE);
                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                            return 0;
                        }
                        return 1;
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        Log.i("zhangxiaoxidebug", "getIndex....onFailure msg=" + msg);
                        Toast.makeText(getApplicationContext(), "读取店铺信息失败，请检查网络设置！", Toast.LENGTH_LONG).show();
                    }
                }
        );
    }

    private void setStoreCredit(int creditNum) {
        LinearLayout.LayoutParams myParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);
        myParams.setMargins(0, 0, 3, 0);
        for (int i = 0; i < creditNum; i++) {
            ImageView creditHeart = new ImageView(this);
            creditHeart.setImageResource(R.drawable.store_xin);
            storemainCreditLl.addView(creditHeart, myParams);
        }
    }

    private void changeYHQ(String yhqId) {
        String url = "http://www.xilingou.com/mobile/index.php?act=goods&op=dhdjj&member_id="
                + MainActivity.myLogin.getMemberid() + "&vid=" + yhqId;
        HttpUtils http = new HttpUtils();
        http.configCurrentHttpCacheExpiry(2000);
        http.send(HttpRequest.HttpMethod.GET, url, new RequestCallBack<String>() {
                    @Override
                    public void onLoading(long total, long current, boolean isUploading) {
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        String result = responseInfo.result;
                        Log.i("zhangxiaoxidebug", "change_yhq=" + result);
                        try {
                            JSONObject jsObjectCode = new JSONObject(result);
                            String datastr = jsObjectCode.getString("data");
                            Toast.makeText(getApplicationContext(), datastr, Toast.LENGTH_LONG).show();
                        } catch (JSONException e) {
                            Toast.makeText(getApplicationContext(), "优惠券兑换失败，请联系客服处理！", Toast.LENGTH_LONG).show();
                            e.printStackTrace();
                        }
                    }


                    @Override
                    public void onStart() {

                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        Toast.makeText(getApplicationContext(), "优惠券兑换失败，请检查网络设置！", Toast.LENGTH_LONG).show();
                    }
                }
        );
    }

    private void getYHQInfo() {
        String url = "http://www.xilingou.com/mobile/index.php?act=goods&op=pointvoucher&store_id=" + StoreID;
        HttpUtils http = new HttpUtils();
        http.configCurrentHttpCacheExpiry(2000);
        http.send(HttpRequest.HttpMethod.GET, url, new RequestCallBack<String>() {
                    @Override
                    public void onLoading(long total, long current, boolean isUploading) {
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        int result = parseProject(responseInfo.result);
                        switch (result) {
                            case 1:
                                break;
                            case 0:
                                Toast.makeText(getApplicationContext(), "读取店铺优惠券失败！", Toast.LENGTH_LONG).show();
                                break;
                            default:
                                break;
                        }
                    }


                    @Override
                    public void onStart() {

                    }

                    private int parseProject(String result) {
                        Log.i("zhangxiaoxidebug", "yhq_result=" + result);
                        try {
                            JSONObject jsObjectCode = new JSONObject(result);
                            String datastr = jsObjectCode.getString("datas");
                            if (datastr.equals("is null")) {
                                storeYouhuiquanRv.setVisibility(View.GONE);
                                return 1;
                            }
                            storeYouhuiquanRv.setVisibility(View.VISIBLE);
                            JSONArray jsArrayDatas = new JSONArray(datastr);

                            //优惠券列表
                            {
                                goodsYHQLists.clear();
                                for (int i = 0; i < jsArrayDatas.length(); i++) {
                                    JSONObject jsObjectTheGood = jsArrayDatas.getJSONObject(i);
                                    String voucher_t_id = jsObjectTheGood.getString("voucher_t_id");
                                    String voucher_t_title = jsObjectTheGood.getString("voucher_t_title");
                                    String voucher_t_desc = jsObjectTheGood.getString("voucher_t_desc");
                                    String voucher_t_start_date = jsObjectTheGood.getString("voucher_t_start_date");
                                    String voucher_t_end_date = jsObjectTheGood.getString("voucher_t_end_date");
                                    String voucher_t_price = jsObjectTheGood.getString("voucher_t_price");
                                    String voucher_t_limit = jsObjectTheGood.getString("voucher_t_limit");
                                    String voucher_t_store_id = jsObjectTheGood.getString("voucher_t_store_id");
                                    String voucher_t_state = jsObjectTheGood.getString("voucher_t_state");
                                    String voucher_t_add_date = jsObjectTheGood.getString("voucher_t_add_date");
                                    goodsYHQLists.add(new YouHuiQuanBean(voucher_t_id, voucher_t_id, voucher_t_id, voucher_t_title, voucher_t_desc,
                                            voucher_t_start_date, voucher_t_end_date, voucher_t_price, voucher_t_limit, voucher_t_store_id, voucher_t_state, voucher_t_add_date, voucher_t_desc));
                                }
                                recycleYHQViewAdapter.notifyDataSetChanged();
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                            return 0;
                        }
                        return 1;
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        Log.i("zhangxiaoxidebug", "getIndex....onFailure msg=" + msg);
                        Toast.makeText(getApplicationContext(), "读取店铺优惠券失败，请检查网络设置！", Toast.LENGTH_LONG).show();
                    }
                }
        );
    }

    private void storeSaveSet() {
        String url = "http://www.xilingou.com/mobile/index.php?act=goods&op=store_fav&store_id=" + StoreID + "&member_id=" + MainActivity.myLogin.getMemberid();
        Log.i("zhangxiaoxidebug", "detail url =" + url);
        HttpUtils http = new HttpUtils();
        http.configCurrentHttpCacheExpiry(200);
        http.send(HttpRequest.HttpMethod.GET, url, new RequestCallBack<String>() {
                    @Override
                    public void onLoading(long total, long current, boolean isUploading) {
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        int result = parseProject(responseInfo.result);
                        switch (result) {
                            case 1:
                                break;
                            case 0:
                                Toast.makeText(getApplicationContext(), "收藏操作失败！", Toast.LENGTH_LONG).show();
                                break;
                            default:
                                break;
                        }
                    }

                    @Override
                    public void onStart() {
                        storeSavestoreLl.setClickable(false);
                    }

                    private int parseProject(String result) {
                        Log.i("zhangxiaoxidebug", "save_result=" + result);
                        try {
                            JSONObject jsObjectCode = new JSONObject(result);
                            int code = jsObjectCode.getInt("code");
                            if (code != 200) {
                                return 0;
                            }

                            JSONObject jsObjectDatas = jsObjectCode.getJSONObject("datas");
                            int is_fav = jsObjectDatas.getInt("is_fav");
                            if (is_fav > 0) {
                                storeSavestoreIv.setImageDrawable(getResources().getDrawable(R.drawable.cang));
                                storeSavestoreTv.setText("已收藏");
                            } else {
                                storeSavestoreIv.setImageDrawable(getResources().getDrawable(R.drawable.dian_love));
                                storeSavestoreTv.setText("收藏");
                            }
                            storeSavestoreLl.setClickable(true);
                        } catch (JSONException e) {
                            e.printStackTrace();
                            return 0;
                        }
                        return 1;
                    }

                    @Override
                    public void onFailure(HttpException error, String msg) {
                        Log.i("zhangxiaoxidebug", "getIndex....onFailure msg=" + msg);
                        Toast.makeText(getApplicationContext(), "收藏操作失败，请检查网络设置！", Toast.LENGTH_LONG).show();
                    }
                }
        );
    }

}
